def check(t, s):
    ans = 0
    flag = True
    if t[0] != s[0] or t[-1] != s[-1]:
        flag = False
    for i in range(1, len(t) - 1):
        if t[i] != s[i]:
            if  s[i-1] == s[i+1]:
                ans += 1
            else:
                flag = False
    return flag, ans

d = int(input())
for _ in range(d):
    t = input()
    s = input()
    flag, ans = check(t, s)
    print(ans if flag else -1)
